package cn.dengta.webapp.im.entity;

import java.util.Date;
import javax.annotation.Nullable;

import cn.dengta.common.model.Status;
import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.model.ValueProxyImpl;
import cn.dengta.common.util.Common;
import cn.dengta.context.model.LabelI18nProxy;
import cn.dengta.webapp.base.entity.BizEntity;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import static cn.dengta.context.model.ImEnumI18nKey.*;

/**
 * 缘分雷达速配表
 *
 * @author lgy
 * @since 2022-07-23
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("im_fate_radar")
public class FateRadar extends BizEntity {

	/** 用户ID */
	private Long userId;
	/** 类型 */
	private Type type;
	/** 雷达类型 */
	private RadarType radarType;
	/** 是否使用 */
	private Integer isUse;

	public FateRadar init(Long userId, Date now) {
		this.id = userId;
		this.userId = userId;
		this.type = Type.STD;
		this.isUse = 1;
		super.init(null, null);
		super.initTime(now);
		return this;
	}

	public boolean use() {
		return Status.asResult(isUse);
	}

	@Override
	public boolean isEnabled() {
		return Status.asResult(status);
	}

	public boolean isAnchor() {
		return type == Type.ANCHOR;
	}

	public static final String USER_ID = "user_id";
	public static final String TYPE = "type";
	public static final String PAIR_TIMES = "pair_times";
	public static final String GREET_TIMES = "greet_times";
	public static final String IS_USE = "is_use";
	public static final String SLOGAN = "slogan";

	@Getter
	public enum Type implements ValueProxyImpl<Type, Integer> {

		/** 用户 */
		STD(0, "用户"),
		/** 女主播 */
		ANCHOR(1, "女主播"),
		//
		;

		// 定义私有变量
		public final Integer value;
		final ValueProxy<Type, Integer> proxy;

		// 构造函数，枚举类型只能为私有
		Type(Integer value, String label) {
			this.value = value;
			this.proxy = new ValueProxy<>(this, value, label);
		}

		public static final Type[] CACHE = values();

		public static Type of(@Nullable Integer value) {
			return Common.getEnum(CACHE, Type::getValue, value);
		}

	}

	@Getter
	public enum RadarType implements LabelI18nProxy<RadarType, Integer> {

		/** 恋爱 */
		LOVE(0, RADAR_TYPE_LOVE),
		/** 新的朋友 */
		FRIEND(1, RADAR_TYPE_FRIEND),
		/** 约会 */
		DATE(2, RADAR_TYPE_DATE),
		/** 婚姻 */
		MARRIAGE(3, RADAR_TYPE_MARRIAGE),
		//
		;

		// 定义私有变量
		@EnumValue
		public final Integer value;
		final ValueProxy<RadarType, Integer> proxy;

		// 构造函数，枚举类型只能为私有
		RadarType(Integer value, String label) {
			this.value = value;
			this.proxy = new ValueProxy<>(this, value, label);
		}

		public static final RadarType[] CACHE = values();

		public static RadarType of(@Nullable Integer value) {
			return LOVE.getValueOf(value);
		}

	}

}
